﻿@inherits BaseComponent

<input type="hidden" id="@Id" name="@Id" value="@Value" />
<ul class="@Class">
    <li class="@Active()" onclick="@OnItemClick()">全部</li>
    @foreach (var item in Items)
    {
        <li class="@Active(item.Key)" onclick="@OnItemClick(item.Key)">@item.Value</li>
    }
</ul>

@code {
    [Parameter] public string Value { get; set; }
    [Parameter] public Dictionary<string, string> Items { get; set; }
    [Parameter] public Func<string, string> OnClick { get; set; }

    private string OnItemClick(string value = null) => OnClick?.Invoke(value);

    private string Active() => string.IsNullOrWhiteSpace(Value) ? "active" : "";

    private string Active(string value)
    {
        var isActive = !string.IsNullOrWhiteSpace(Value) && Value.Split(',').Contains(value);
        return isActive ? "active" : "";
    }
}